package n2251;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	static int max=30;
	
	static char[][][] maze=new char[max][max][max];
	
	static boolean visited[][][] =new boolean[max][max][max];
	
	static int mins=-1;
	
	static int L,R,C;
	
	static int[][] dir={{-1,0,0},{0,1,0},{1,0,0},{0,-1,0},{0,0,1},{0,0,-1}};
	static void dfs(int x,int y,int z,int count)
	{
		if(mins!=-1&&count>=mins)return;
		visited[x][y][z]=true;
		for(int i=0;i<dir.length;i++)
		{
			int tx=x,ty=y,tz=z;
			tx+=dir[i][0];
			ty+=dir[i][1];
			tz+=dir[i][2];
			if(tx>=0&&tx<L&&ty>=0&&ty<R&&tz>=0&&tz<C)
			{
				if(maze[tx][ty][tz]=='E')
				{
					if(mins==-1)mins=count+1;
					else if(mins>count)mins=count+1;
					return;
				}
				if(!visited[tx][ty][tz]&&maze[tx][ty][tz]=='.')
				{
					visited[tx][ty][tz]=true;
					dfs(tx,ty,tz,count+1);
					visited[tx][ty][tz]=false;
				}
			}
		}
	}
	
	static int [][] list=new int[max*max*max][4];
	
	static void bfs(int x,int y,int z)
	{
		for(int i=0;i<L;i++)
			for(int j=0;j<R;j++)
				for(int k=0;k<C;k++)
					visited[i][j][k]=false;
		
		int i=0,count=1;
		list[0][0]=x;
		list[0][1]=y;
		list[0][2]=z;
		list[0][3]=0;
		visited[x][y][z]=true;
		while(i<count)
		{
			int curx=list[i][0];
			int cury=list[i][1];
			int curz=list[i][2];
			int step=list[i][3];
			for(int j=0;j<dir.length;j++)
			{
				int tx=curx,ty=cury,tz=curz;
				tx+=dir[j][0];
				ty+=dir[j][1];
				tz+=dir[j][2];
				if(tx>=0&&tx<L&&ty>=0&&ty<R&&tz>=0&&tz<C)
				{
					if(maze[tx][ty][tz]=='E')
					{
						if(mins==-1)mins=step+1;
						else if(mins>count)mins=step+1;
						return;
					}
					if(!visited[tx][ty][tz]&&maze[tx][ty][tz]=='.')
					{
						visited[tx][ty][tz]=true;
						list[count][0]=tx;
						list[count][1]=ty;
						list[count][2]=tz;
						list[count][3]=step+1;
						count++;
					}
				}
			}
			i++;
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub

		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		
		String line=null;
		while((line=bf.readLine())!=null)
		{
			StringTokenizer st=new StringTokenizer(line);
			L=Integer.parseInt(st.nextToken());
			R=Integer.parseInt(st.nextToken());
			C=Integer.parseInt(st.nextToken());
			if(L==0&&R==0&&C==0)break;
			int sx=-1,sy=-1,sz=-1;
			for(int i=0;i<L;i++)
			{
				for(int j=0;j<R;j++)
				{
					line=bf.readLine();
					for(int k=0;k<C;k++)
					{
						maze[i][j][k]=line.charAt(k);
						visited[i][j][k]=false;
						if(sx==-1&&maze[i][j][k]=='S'){
							sx=i;
							sy=j;
							sz=k;
						}
					}
				}
				line=bf.readLine();
			}
			mins=-1;
			//dfs(sx, sy, sz, 0);
			bfs(sx,sy,sz);
			if(mins!=-1)
			{
				System.out.println("Escaped in "+mins+" minute(s).");
			}else{
				System.out.println("Trapped!");
			}
		}
		
	}

}
